﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System;
using System.Net;
using System.Security.Principal;

#endregion


namespace ESF.MSReporting
{
	[Serializable]
	public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials 
	{
		#region Miembros
		
		NetworkCredential _NetworkCredential;
		
		#endregion
		
		
		#region Propiedades
		
		public WindowsIdentity ImpersonationUser
		{
			get
			{ 
				return null;  
			}
		}
		public ICredentials NetworkCredentials
		{
			get
			{ 
				return _NetworkCredential;
			}
		}
		
		#endregion
		
		
		#region Constructor
		
		public CustomReportCredentials()
		{
			_NetworkCredential = new NetworkCredential ();
		}
		
		
		public CustomReportCredentials(string pUserName, string pPassword)
			: this (pUserName, pPassword, string.Empty) {}
		
		
		public CustomReportCredentials(string pUserName, string pPassword, string pDomainName)
		{  
			if (string.IsNullOrEmpty (pUserName) || string.IsNullOrEmpty (pPassword))
			{
				_NetworkCredential = new NetworkCredential ();
			}
			else
			{
				_NetworkCredential = new NetworkCredential (pUserName, pPassword, pDomainName);
			}
		}
		
		#endregion
	    
		
	    #region Funciones
	    
		public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
		{ 
			// not use FormsCredentials unless you have implements a custom autentication.
			authCookie = null;
			user = password = authority = null;
			return false;
			
			// TODO: Soportar el manejo del SSO y tomarlo de ahi
			/*userName = _userName;
			password = _password;
			authority = _domain;
			authCookie = new System.Net.Cookie (".ASPXAUTH", ".ASPXAUTH", "/", "Domain");*/

			//return true;
		}
		
		#endregion
	}

}
